package com.ymatou.iapi.productmanager.testcase.old;

import com.ymatou.iapi.productmanager.parameter.SaveGrouponBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.parameter.product.CatalogPropertySaveModel;
import com.ymatou.iapi.productmanager.parameter.product.CatalogSaveModel;
import com.ymttest.business.service.ProductManagerCallServiceV2;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.utils.TestDataManager;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class testRun {

    public static void main(String[] args) throws Exception {
        ExecutorService executor = Executors.newFixedThreadPool(20);
        for (int i = 0; i < 2;i++) {
            executor.submit(()->{
                try {
                    AddSellerProductRequest addpro = ProductManagerCallServiceV3.initAddSellerProductRequest(3383);
                    List<CatalogSaveModel> catalogSaveModels = addpro.getProduct().getCatalogList();
                    for(int j=0;j<8;j++){
                        CatalogSaveModel CatalogSaveModel = new CatalogSaveModel();
                        CatalogSaveModel.setOperateType(1);
                        CatalogSaveModel.setPackage(false);
                        CatalogSaveModel.setPreSale(false);
                        CatalogSaveModel.setNewPrice(Integer.valueOf(10));
                        CatalogSaveModel.setVipPrice(Integer.valueOf(10));
                        CatalogSaveModel.setPrice(Integer.valueOf(20));
                        CatalogSaveModel.setMarketPrice(70);
                        CatalogSaveModel.setAction(0);
                        CatalogSaveModel.setStock(1000000);
                        CatalogSaveModel.setMultiLogistics(0);
                        CatalogSaveModel.setSku("sku-7232f1de-ffbf-49ae-a0bc-d8765456b07f");

                        List<CatalogPropertySaveModel> propertyList = new ArrayList<>();
                        CatalogPropertySaveModel e1 = new CatalogPropertySaveModel();
                        // e.setPropertyId("1");
                        e1.setPropertyName("颜色");
                        e1.setPropertyUrl("http://s2.ymatou.com/home/b5abefb15e5afbb91d82c65df819be22.png");
                        e1.setPropertyValue("红色"+ TestDataManager.getRandomNum(6));
                        propertyList.add(e1);
                        CatalogSaveModel.setPropertyList(propertyList);
                        catalogSaveModels.add(CatalogSaveModel);
                    }
                    setStock(addpro, 30);
                    setPrice(addpro, 100d);
                    String productId = ProductManagerCallServiceV3.AddSellerProduct(addpro);
                    System.out.println("productId:" + productId);

                    SaveGrouponBean saveGrouponBean = ProductManagerCallServiceV3.initSaveGrouponBean(3383,productId,70d);
                    ProductManagerCallServiceV3.SaveGrouponCall(saveGrouponBean);
                } catch (Exception e) {

                }
            });

        }

        while(!executor.isTerminated()){
            Thread.sleep(1000);
            executor.shutdown();
        }

    }

    private static void setStock(AddSellerProductRequest addpro, Integer catalogNum) {
        addpro.getProduct().getCatalogList().forEach(catalog -> {
            catalog.setStock(catalogNum);
        });
    }

    private static void setPrice(AddSellerProductRequest addpro, Double price) {
        addpro.getProduct().getCatalogList().forEach(catalog -> {
            catalog.setNewPrice(price);
            catalog.setMarketPrice(price);
            catalog.setVipPrice(price);
            catalog.setPrice(price);
        });
    }

//    public static Integer getRedis(){
//
//    }

    public static void addProduct() throws Exception {
        AddSellerProductRequest addpro =  ProductManagerCallServiceV2.initAddSellerProductRequest(288484);
        //获取商品ID，单规格
        String productId = ProductManagerCallServiceV2.addNewProduct(addpro).get("Data").getAsJsonObject().get("ProductId").getAsString();

    }



    public static void offSaleAllProduct() throws Exception {
        ProductManagerCallServiceV2.offSaleAllProduct(288484);
    }

}
